package com.changan.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.changan.entity.Menu;
import com.changan.response.Result;
import com.changan.service.MenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 菜单表 前端控制器123456
 * </p>
 *
 * @author NieChangan
 * @since 2022-03-02
 */
@CrossOrigin
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 加载菜单树
     *
     * @return
     */
    @ApiOperation(value = "加载菜单树", notes = "获取所有菜单树，以及展开项")
    @GetMapping("/tree")
    public Result tree() {
        //查询所有的菜单
        List<Menu> menuTree = menuService.findMenuTree();
        //jdk8的流
        //获取menu表中的open列
        List<Integer> ids = menuTree.stream()
                .map(menu -> menu.getOpen())
                .collect(Collectors.toList());
        return Result.ok().data("tree",menuTree).data("open",ids);
    }
}

